package net.comm.file.db;

import org.sakaiproject.db.api.iServiceSql;


/**
 * methods for accessing user data in a database.
 */
public class FilesServiceSqlMysql implements iServiceSql
{
	/**
	 * 返回根据主键删除语句
	 */
	public String getDeleteSql()
	{
		return "delete from Files" +
				" where F_ID=?";
	}

	/**
	 * 返回插入语句
	 */
	public String getInsertSql()
	{
		return "insert  into Files" +
				" ( f_ID, f_info, folder, f_name, F_File2, f_Num, f_Type, f_Zip, f_size,  mtime )" +
				" values (?,?,?,?,?,?,?,?,?,?)";
	}
	
	/**
	 * 返回根据主键修改语句
	 */
	public String getUpdateSql()
	{
		return "update Files" +
				"  set f_info=?, folder=?, f_name=?, F_File2=?, f_Num=?, f_Num=?, f_Type=?, f_Type=?, f_Zip=?, f_size=?,  mtime=? " +
				"  where F_ID=?";
	}

	/**
	 * 返回根据主键查询语句
	 */
	public String getbykeySql()
	{
		return "select f_ID, f_info, folder, f_name, F_File2, f_Num, f_Type, f_Zip, f_size,  mtime " +
				" from Files" +
				" where F_ID=?";
	}
	
	/**
	 * return the sql statement which updates an external user id for a given user in the sakai_user_id_map table.
	 */
	public String getRecbyPageSql()
	{
	
		StringBuffer sb =  new StringBuffer("select f_ID, f_info, folder, f_name, F_File2, f_Num, f_Type, f_Zip, f_size,  mtime  " +
				" from Files" );
		
		sb.append(" where 1=1 Order by mtime desc ");
		sb.append(" limit ?, ?");
				
		return sb.toString();	
	}	
	/**
	 * return the sql statement which updates an external user id for a given user in the sakai_user_id_map table.
	 */
	public String getRecSql()
	{
	
		StringBuffer sb =  new StringBuffer("select f_ID, f_info, folder, f_name, F_File2, f_Num, f_Type, f_Zip, f_size,  mtime " +
				" from Files" );
		return sb.toString();	
	}	

	/**
	 * 返回所有记录数
	 */
	public String getCountSql1()
	{
		return "select count(*) as COUNT from Files";
	}

	/**
	 * 返回根据查询条件的记录数
	 */
	public String getCountSql2()
	{
		return "select count(*) as COUNT from Files" +
				" where f_Type=? ";
	}


	/**
	 * @see net.comm.job.db.iServiceSql.impl.FileserviceSql#getMaxInputsForSelectWhereInQueries()
	 */
	public int getMaxInputsForSelectWhereInQueries() {
		// For Oracle, the maximum supported number of expressions in a list is 1000. 
		return 1000;
	}
}
